package com.efesco.service.archives;

import java.util.List;

import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.DBStatement;
import com.bstek.dorado.data.db.SqlDataset;
import com.bstek.dorado.utils.variant.VariantSet;
import com.bstek.dorado.common.*;
import com.efesco.common.CommUtil;

/**
 * V_employee_file_intro_letter_dataset_file_intro_letterListener
 */
public class V_employee_file_intro_letter_dataset_file_intro_letterListener
		extends AbstractDatasetListener {
	public boolean beforeLoadData(Dataset dataset) throws Exception {
		String employee_on_off_id = (String) dataset.parameters().getValue(
				"employee_on_off_id");

		dataset.insertRecord();

		DBStatement dbs = new DBStatement();

		String sql1 = "SELECT ai.*,eoop.employee_on_off_id,emp.employee_name emp_name,sc.company_chinese_name FROM "
				+ "s_archives_intro ai,s_employee_on_off_post eoop,s_employee emp,s_single_company sc WHERE "
				+ "eoop.single_company_id=sc.single_company_id and "
				+ "eoop.employee_id=emp.employee_id and "
				+ "ai.employee_on_off_id=eoop.employee_on_off_id and  ai.employee_on_off_id="
				+ employee_on_off_id;
		dbs.setSql(sql1);
		List list1 = dbs.queryForList();
		if (list1.size() > 0) {
			VariantSet rs1 = (VariantSet) list1.get(0);
			dataset.setValue("ARCHIVES_INTRO_ID", rs1
					.getValue("ARCHIVES_INTRO_ID"));
			dataset.setValue("OPEN_LETTER_DATE", rs1
					.getValue("OPEN_LETTER_DATE"));
			dataset.setValue("INFORM_OPEN_LETTER_MAN", rs1
					.getValue("INFORM_OPEN_LETTER_MAN"));
			dataset.setValue("EMPLOYEE_NAME", rs1.getValue("EMPLOYEE_NAME"));
			dataset.setValue("CONSIGN_UNIT", rs1.getValue("CONSIGN_UNIT"));
			dataset.setValue("CONSIGN_UNIT_name", rs1
					.getValue("COMPANY_CHINESE_NAME"));
			dataset.setValue("EMPLOYEE_NAME_str", rs1.getValue("emp_name"));
			dataset.setValue("EMPLOYEE_ID_CARD_NUM", rs1
					.getValue("EMPLOYEE_ID_CARD_NUM"));
			dataset.setValue("FILE_AREA", rs1.getValue("FILE_AREA"));
			dataset.setValue("MOVE_FILE_OPERATOR", rs1
					.getValue("MOVE_FILE_OPERATOR"));
			dataset.setValue("APPLY_DATE", rs1.getValue("APPLY_DATE"));
			dataset.setValue("INTRO_LETTER_CODE", rs1
					.getValue("INTRO_LETTER_CODE"));
			dataset.setValue("MOVE_TO_DATE", rs1.getValue("MOVE_TO_DATE"));
			dataset.setValue("REMARK", rs1.getValue("REMARK"));
			dataset.setValue("employee_on_off_id", rs1
					.getValue("employee_on_off_id"));

		} else {

			String sql = "SELECT "
					+ "emp.employee_name,sc.company_chinese_name,emp.employee_id,sc.single_company_id "
					+ "FROM "
					+ "s_employee_on_off_post eoop,s_employee emp,s_single_company sc "
					+ "WHERE "
					+ "eoop.single_company_id=sc.single_company_id and "
					+ "eoop.employee_id=emp.employee_id and "
					+ "eoop.employee_on_off_id=" + employee_on_off_id;
			dbs.setSql(sql);
			List list = dbs.queryForList();
			VariantSet rs2 = (VariantSet) list.get(0);

			dataset.setValue("CONSIGN_UNIT", rs2.getValue("SINGLE_COMPANY_ID"));
			dataset.setValue("CONSIGN_UNIT_name", rs2
					.getValue("COMPANY_CHINESE_NAME"));
			dataset.setValue("EMPLOYEE_NAME", rs2.getValue("EMPLOYEE_ID"));
			dataset
					.setValue("EMPLOYEE_NAME_str", rs2
							.getValue("EMPLOYEE_NAME"));

		}
		dbs.close();
		return true;
	}

}
